﻿Imports System.Data.SqlClient

Public Class successcase
    Inherits System.Web.UI.Page
    Dim objrd As SqlDataReader = Nothing
    Private i As Integer
    Private pages As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sSQL As String = ""
        Dim sum, sumdesc As Integer
        Dim objdt As New GetData
        Dim ps As New PreparedStatement(sSQL)
        Dim comId As String
        Dim strErr As String = ""
        comId = Request("cid")
        i = Request("page")
        If i = Nothing Or i = 0 Then
            i = 1
        End If
        Dim conn As SqlConnection = objdt.getConn()
        If comId <> Nothing And comId <> "" Then
            ps.addParameter("cid", comId)
            sSQL = "select *  from  merchant_info where company_id=@cid and lang_flag='en'"
            ps.strSql = sSQL
            objrd = objdt.dr(ps, strErr, conn, objrd)
            If Not objrd.Read() Then
                objdt.closeConn(conn)

                Exit Sub
            End If
            title.InnerHtml += ":" & objrd.Item("company_name").ToString
            companyName.InnerText = objrd.Item("company_name").ToString
            sSQL = "select count(*)  from  company_successcase where company_id=@cid and lang_flag='en'"
            ps.strSql = sSQL
            objrd = objdt.dr(ps, strErr, conn, objrd)
            objrd.Read()
            sum = objrd.Item(0)
            pages = sum / 10 + 1
            If i >= pages Then
                i = pages
            ElseIf i <= 0 Then
                i = 1
            End If
            If (i = pages) Then
                sumdesc = sum
            Else
                sumdesc = i * 10
            End If
            sSQL = "select top(" & i & "*10) * from company_successcase where company_id=@cid and lang_flag='en' " & _
                    "and id not in (" & _
                    "select top (" & i - 1 & "*10) id from company_successcase where company_id=@cid and lang_flag='en' " & _
                    "order by create_Date" & _
                    ") and id not in (select top(" & sum - sumdesc & ") id from company_successcase where company_id=@cid and lang_flag='en' " & _
                    "order by create_Date desc) order by create_Date"

            'sSQL = "select top (" & i & "*10) * from  company_successcase where company_id=@cid and lang_flag='en' and id not in (select top ((" & i & "-1)*10) id from company_successcase where company_id=@cid and lang_flag='en' order by create_Date Desc) order by create_Date Desc"
            ps.strSql = sSQL
            objrd = objdt.dr(ps, strErr, conn, objrd)
            successCase.InnerHtml = "<table width=""100%"">"
            While (objrd.Read())
                successCase.InnerHtml += "<tr>"
                successCase.InnerHtml += "<td><label><a href=""successcase_info?sid=" & objrd("id").ToString & """>" & objrd("title").ToString & "</a></label></td>"
                successCase.InnerHtml += "<td  width=""200px"" ><label>" & Year(objrd("create_Date")) & "/" & Month(objrd("create_Date")) & "/" & Day(objrd("create_Date")) & "</label></td>"
                successCase.InnerHtml += "</tr>"
            End While
            successCase.InnerHtml += "</table>"
            pageDiv.InnerHtml += "<label  id=""firstPage"" ><a href=""successcase.aspx?cid=" & comId & "&page=1"">First Page</a></label>  "
            pageDiv.InnerHtml += "<label  id=""previousPage"" ><a href=""successcase.aspx?cid=" & comId & "&page=" & i - 1 & """>Previous Page</a></label>  "
            pageDiv.InnerHtml += "<label  id=""nextPage"" ><a href=""successcase.aspx?cid=" & comId & "&page=" & i + 1 & """>Next Page</a></label>  "
            pageDiv.InnerHtml += "<label  id=""lastPage"" ><a href=""successcase.aspx?cid=" & comId & "&page=" & pages & """>Last Page</a></label>"

        Else
            Response.Redirect("index.aspx")
        End If
        objdt.closeConn(conn)
    End Sub

End Class